package cn.gson.work.model.service;

import cn.gson.work.model.mapper.UserMapper;
import cn.gson.work.model.pojos.User;
import cn.gson.work.model.vo.UserQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserService {
    @Autowired
    UserMapper userbiz;

    /**
     * 分页查询用户信息
     * @param query
     * @return
     */
    public Map<String,Object> getUserByQuery(UserQuery query){
        Map<String,Object> map = new HashMap<String,Object>();
        PageHelper.startPage(query.getCurpage(),query.getPagesize());
        List<User> list = userbiz.getUserByQuery(query);
        PageInfo<User> info = new PageInfo<>(list);
        map.put("list",list);
        map.put("total",info.getTotal());
        return map;
    }

    /**
     * 新增用户信息
     * @param user
     */
    public void addUser(User user){
        System.out.println(user.toString());
        userbiz.addUser(user);
    }

    /**
     * 修改用户信息
     * @param user
     */
     public void editUser(User user){
        userbiz.editUser(user);
     }
}
